<?php

namespace App\Http\Model\Admin;

use Illuminate\Database\Eloquent\Model;

class TouristInfo extends Model
{
    //  table name
    protected $table = 'tourists_info';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'phone', 'name', 'business_area', 'business_area_ids', 'district', 'district_ids', 'price', 'area', 'remark', 'cityarea_id', 'cityarea_name', 'house_room', 'house_hall', 'house_toilet', 'page_type'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [

    ];

    /**
     * find one user by id
     *
     * @param  id
     * @return  model
     */
    public function findOneById($id)
    {
        $one = self::find($id);
        return $one;
    }

    /**
     * find one by phone
     *
     * @param  user_id
     * @return  model list
     */
    public function findOneByPhone($phone)
    {
        $one = self::where('phone', $phone)->first();
        return $one;
    }

    /**
     * find one by name
     *
     * @param  name
     * @return  model
     */
    public function findOneByName($name = '')
    {
        $one = self::where('name', $name)->first();
        return $one;
    }

    /**
     * find list by pageinate default 15
     *
     * @param  per_page
     * @return page info with  model list
     */
    public function findAllByPaginate($per_page = 15, $input = [])
    {
        return self::paginate($per_page);
    }

    /**
     * update one by id
     *
     * @param  id
     * @param  $input object
     * @return  boolean
     */
    public function updateOneById($id, $input)
    {
        return self::where('id', $id)->update($input);
    }



    public function updateInfo($phone, $data)
    {
        $record = $this->findOneByPhone($phone);

        $info = array(
            'phone' => $data['phone'],
            'name' => $data['appName'],
            'city' => $data['city'],
            'business_area' => $data['business_area'],
            );

        if (count($record) == 0 || !$record) {

        }

    }

}
